function allowEdit(){

	document.getElementById('questionTitle').disabled=false;;
	document.getElementById('category').disabled=false;
	document.getElementById('url').disabled=false;;
	document.getElementById('initialQuestion').disabled=false;
	document.getElementById('yesQuestioncChkbox').disabled=false;
	document.getElementById('noQuestioncChkbox').disabled=false;
	document.getElementById('yesQuestionUrl').disabled=false;
	document.getElementById('noQuestionUrl').disabled=false;


	if(document.getElementById('yesQuestioncChkbox').checked==true){

		document.getElementById('yesQuestion').disabled=true;
		document.getElementById('yesDiagnosis').disabled=false;
	}else{
		document.getElementById('yesQuestion').disabled=false;
		document.getElementById('yesDiagnosis').disabled=true;
	}

	if(document.getElementById('noQuestioncChkbox').checked==true){

		document.getElementById('noQuestion').disabled=true;
		document.getElementById('noDiagnosis').disabled=false;
	}else{
		document.getElementById('noQuestion').disabled=false;
		document.getElementById('noDiagnosis').disabled=true;
	}

}

function previousPage(type){

        if(document.getElementById("nestingLevel").value > 3){
		if(type==2)
			document.submitAll.action='edit2.php';
		else 
            		document.submitAll.action='create2.php';
        }else{
		if(type==2)
			document.submitAll.action='edit.php';
		else 
            		document.submitAll.action='create.php';
        }
        document.getElementById("previous").value='true';
        document.getElementById("nestingLevel").value = (document.getElementById("nestingLevel").value - 2);
    }


function show(left,check, right){
    
    if(document.getElementById(check).checked == true){
        document.getElementById(left).value="";
        document.getElementById(left).disabled = true;
        document.getElementById(right).disabled = false;
    }else{
         document.getElementById(right).value="";
        document.getElementById(left).disabled =false ;
        document.getElementById(right).disabled = true;
    }
}


   function enableAll()
    {
    	var theForm = document.forms[0];

    	for(var i=0; i<theForm.elements.length; i++){
    	                           
    		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea"){
    			theForm.elements[i].disabled=false;
    		}
    	}
    }

   function disableAll(theForm)
    {

			for(var i=0; i<theForm.elements.length; i++){
									   
				if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" 
						|| theForm.elements[i].type == "checkbox"){
					theForm.elements[i].disabled=false;
				}
			}
    }


function allowEditAll(questionid){


	document.getElementById('yesQuestioncChkbox'+questionid).disabled=false;
	document.getElementById('noQuestioncChkbox'+questionid).disabled=false;

	document.getElementById('yesQuestionUrl'+questionid).disabled=false;
	document.getElementById('noQuestionUrl'+questionid).disabled=false;


	if(document.getElementById('yesQuestioncChkbox'+questionid).checked==true){

		document.getElementById('yesQuestion'+questionid).disabled=true;
		document.getElementById('yesDiagnosis'+questionid).disabled=false;
	}else{
		document.getElementById('yesQuestion'+questionid).disabled=false;
		document.getElementById('yesDiagnosis'+questionid).disabled=true;
	}

	if(document.getElementById('noQuestioncChkbox'+questionid).checked==true){

		document.getElementById('noQuestion'+questionid).disabled=true;
		document.getElementById('noDiagnosis'+questionid).disabled=false;
	}else{
		document.getElementById('noQuestion'+questionid).disabled=false;
		document.getElementById('noDiagnosis'+questionid).disabled=true;
	}

}

function defaultTitleURL(questionid){


			document.getElementById('url').value = createValidURL(document.getElementById('initialQuestion').value);

}

function defaultYesURL(questionid){

	if(document.getElementById('yesQuestionUrl'+questionid).disabled==false){
		if(document.getElementById('yesQuestion'+questionid).disabled==false){
			document.getElementById('yesQuestionUrl'+questionid).value = createValidURL(document.getElementById('yesQuestion'+questionid).value);
		}else{
			document.getElementById('yesQuestionUrl'+questionid).value = createValidURL(document.getElementById('yesDiagnosis'+questionid).value);
		}
	}
}

function defaultNoURL(questionid){

	if(document.getElementById('noQuestionUrl'+questionid).disabled==false){
		if(document.getElementById('noQuestion'+questionid).disabled==false){
			document.getElementById('noQuestionUrl'+questionid).value = createValidURL(document.getElementById('noQuestion'+questionid).value);
		}else{
			document.getElementById('noQuestionUrl'+questionid).value = createValidURL(document.getElementById('noDiagnosis'+questionid).value);
		}
	}
}


function createValidURL(checkStr){

var checkOK = "abcdefghijklmnopqrstuvwxyz0123456789-";
if(checkStr.length>70){
checkStr=checkStr.substring(0,70);

}
checkStr = checkStr.toLowerCase();

for (i = 0;  i < checkStr.length;  i++)
{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++){
		if (ch == checkOK.charAt(j))		
		break;

		if (j == checkOK.length-1)
		{
			
			checkStr = checkStr.replace(ch, "-");
			break;
		}
	}
}


return checkStr;

}

function clearURL(qURL){
document.getElementById(qURL).value="";

}
